package vn.edu.ptithcm.pim.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import vn.edu.ptithcm.pim.dom.TaskStatus;

@SuppressWarnings({ "rawtypes" })
public class TaskStatusDao extends HibernateDaoSupport {

	public void save(TaskStatus taskStatus) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().save(taskStatus);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void saveOrUpdate(TaskStatus taskStatus) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().saveOrUpdate(taskStatus);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void lock(TaskStatus taskStatus) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().lock(taskStatus, LockMode.NONE);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void delete(TaskStatus taskStatus) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().delete(taskStatus);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public TaskStatus merge(TaskStatus taskStatus) {
		try {
			return (TaskStatus) getHibernateTemplate().merge(taskStatus);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public TaskStatus findById(java.lang.Long id) {
		try {
			return (TaskStatus) getHibernateTemplate()
					.get(TaskStatus.class, id);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List findByExample(TaskStatus taskStatus) {
		try {
			return getHibernateTemplate().findByExample("TaskStatus",
					taskStatus);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List getAll() {
		try {
			return getHibernateTemplate().loadAll(TaskStatus.class);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<TaskStatus> findByIdList(List<Long> idList) {
		try {
			Criteria c = getSession().createCriteria(TaskStatus.class);
			c.add(Restrictions.in("statusid", idList));
			return c.list();
		} catch (RuntimeException re) {
			throw re;
		}
	}
}
